#include "XmlConfBase.h"
#include <string>
#include <exception/NpException.h>

using namespace std;
using namespace npexception;

const char g_confDirEnv[] = "NP_CONFIG";
const int g_fileNameLength = 1024;

XmlConfBase::XmlConfBase()
{
  isNull();
}

XmlConfBase::XmlConfBase(const string& fileName)
{
  setFileName(fileName);
}

XmlConfBase::~XmlConfBase()
{
}

void XmlConfBase::initializeConfigs()
{
  static string conf;
  initializeConfigs(conf);
}

void XmlConfBase::initializeConfigs(string& path)
{
  static pugi::xml_document pugixml;
  pugixml.empty();
//  static std::string conf;
  combine(m_fileName, path);
  npexception::throwExIf(pugixml.load_file(path.c_str()) == false, npexception::CONFIG_FILE_LOAD_ERROR);
  todo(pugixml);
}

const pugi::xpath_node* XmlConfBase::getFirstNode(const std::string &path, const pugi::xml_document &pugixml)
{
  static pugi::xpath_node_set nodeSet;
  nodeSet = pugixml.select_nodes(path.c_str());
  return &(nodeSet[0]);
}

void XmlConfBase::isNull()
{
  m_fileName = "";
}
